from apscheduler.schedulers.background import BackgroundScheduler
import time


def job():
    print("Task executed at", time.strftime("%Y-%m-%d %H:%M:%S"))


scheduler = BackgroundScheduler()
scheduler.add_job(job, 'interval', seconds=1)
scheduler.start()

try:
    while True:
        time.sleep(2)
except KeyboardInterrupt:
    scheduler.shutdown()
